#include "Myvector.hpp"

void Test1(){
  Myvector<int> v1;
  v1.push_back(1);
  v1.push_back(2);
  v1.push_back(3);
  v1.push_back(4);
  for(size_t i = 0; i<v1.size(); ++i)
  {
    cout << v1[i] << " ";
  }
  cout << endl;
  v1.pop_back();
  v1.pop_back();
  for(size_t i = 0; i<v1.size(); ++i)
  {
    cout << v1[i] << " ";
  }
  cout << endl;
}

void Test2(){
  Myvector<int> v1;
  v1.push_back(1);
  v1.push_back(2);
  v1.push_back(3);
  v1.push_back(4);
  v1.push_back(1);
  v1.push_back(2);
  v1.push_back(3);
  v1.push_back(4);
  v1.push_back(1);
  v1.push_back(2);
  v1.push_back(3);
  v1.push_back(4);
  v1.push_back(1);
  v1.push_back(2);
  v1.push_back(3);
  v1.push_back(4);
}

void Test3(){
  Myvector<int> v1;
  v1.push_back(1);
  v1.push_back(2);
  v1.push_back(4);
  for(size_t i = 0; i<v1.size(); ++i)
  {
    cout << v1[i] << " ";
  }
  cout << endl;
  v1.insert(&v1[2], 3);
  v1.insert(v1.end(), 5);
  v1.insert(v1.end(), 6);
  for(size_t i = 0; i<v1.size(); ++i)
  {
    cout << v1[i] << " ";
  }
  cout << endl;

}

void Test4(){
  Myvector<int> v1;
  v1.insert(v1.end(), 1);
  v1.insert(v1.end(), 2);
  v1.insert(v1.end(), 3);
  v1.insert(v1.end(), 4);
  v1.insert(v1.end(), 5);
  for(auto e : v1){
    cout << e << " ";
  }
  cout << endl;
  v1.erase(v1.begin()+1);
  v1.erase(v1.begin()+2);
  for(int e : v1){
    cout << e << " ";
  }
  cout << endl;
  v1.erase(v1.begin());
  v1.erase(v1.end()-1);
  for(int e : v1){
    cout << e << " ";
  }
  cout << endl;
}

void Test5(){
  Myvector<int> v1;
  cout << "size: " << v1.size() << " " << "capacity: " << v1.capacity() << endl;
  v1.reserve(10);
  cout << "size: " << v1.size() << " " << "capacity: " << v1.capacity() << endl;
  for(int e : v1){
    cout << e << " ";
  }
  cout << endl;
  v1.resize(20, 2);
  cout << "size: " << v1.size() << " " << "capacity: " << v1.capacity() << endl;
  for(int e : v1){
    cout << e << " ";
  }
  cout << endl;
  v1.resize(30, 1);
  cout << "size: " << v1.size() << " " << "capacity: " << v1.capacity() << endl;
  for(int e : v1){
    cout << e << " ";
  }
  cout << endl;
}

void Test6(){
  Myvector<int> v1(10,10);
  cout << "v1: ";
  for(int e:v1)
  {
    cout << e << " ";
  }
  cout << endl;
  Myvector<int> v2 = v1;
  cout << "v2: ";
  for(int e:v2)
  {
    cout << e << " ";
  }
  cout << endl;
  int arr[] = {0,0,1,2,3,0,0};
  Myvector<int> v3(arr+2, arr+5);
  cout << "v3: ";
  for(int e:v3)
  {
    cout << e << " ";
  }
  cout << endl;
  v2 = v3;
  cout << "v2: ";
  for(int e:v2)
  {
    cout << e << " ";
  }
  cout << endl;
  
}

//在所有偶数前插入此数的10倍
void Test7(){
  int arr[] = {1,2,3,4,5};
  Myvector<int> v1(arr,arr+sizeof(arr)/sizeof(arr[0]));
  Myvector<int>::iterator it = v1.begin();
  while(it != v1.end())
  {
    if(*it % 2 == 0)
    {
      it = v1.insert(it, (*it) * 10);
      ++it;
    }
    ++it;
  }

  for(int e : v1)
  {
    cout << e << " ";
  }
  cout << endl;
}

//删除数列中所有的偶数
void Test8(){
  int arr[] = {1,2,2,3,4,4,4};
  Myvector<int> v1(arr,arr+sizeof(arr)/sizeof(arr[0]));
  Myvector<int>::iterator it = v1.begin();
  while(it != v1.end())
  {
    if(*it % 2 == 0)
    {
      it = v1.erase(it);
    }
    else{
      ++it;
    }
  }

  for(int e : v1)
  {
    cout << e << " ";
  }
  cout << endl;
  
}

class Solution {
public:
    Myvector<Myvector<int>> generate(int numRows) {
        Myvector<Myvector<int>> vv;
        vv.resize(numRows);
        for(size_t i = 0; i<vv.size(); ++i)
        {
            vv[i].resize(i+1);
            vv[i].front() = 1;
            vv[i].back() = 1;
        }
        for(size_t i = 2; i<vv.size(); ++i)
        {
            for(size_t j = 1; j<vv[i].size()-1; ++j)
            {
                vv[i][j] = vv[i-1][j] + vv[i-1][j-1];
            }
        }
        return vv;
    }
};

int main(){
  //Test8();
  Myvector<Myvector<int>> ret = Solution().generate(5);

  for(size_t i = 0; i<ret.size(); ++i)
  {
    for(size_t j = 0; j<ret[i].size(); ++j)
    {
      cout << ret[i][j] << " ";
    }
    cout << endl;
  }
  
  return 0;
}
